/**
 * gbl
 * 搜索结果界面js文件（加载信息）
 * 创建时间：9.19 16:38
 */


function getQueryVariable() {
    let query = window.location.search.substring(1);
    let pair = query.split("=");
    return pair;
}

$(function () {
    var area = getQueryVariable();
    var str=area[0];
    var thearea = decodeURI(area[1]);
    if (str == "area"){
        $.ajax({
            url: "/area/setArea",
            data: {"theArea": thearea},
            success: function (data) {
                addInfo();
            }
        });
    } else if(str == "label"){
        $.ajax({
            url: "/label/setLabel",
            data: {"theArea": thearea},
            success: function (data) {
                addInfo2();
            }
        });
    }
    $("#thisTitle").html(thearea)

});


function addInfo() {
    // 综合排序
    var addFood01 = '/area/areaFood1';
    // 评分排序
    var addFood02 = '/area/areaFood2';
    // 销量排序
    var addFood03 = '/area/areaFood3';
    // 价格排序
    var addFood04 = '/area/areaFood4';
    getFood01();
    getFood02();
    getFood03();
    getFood04();
// 添加热门食品
    function getFood01() {
        $.getJSON(addFood01, function (data){
            if (!data.success){
                var showInfo = '';
                data.areaFood.map(function (item,index) {
                    showInfo += '<div class="col-md-1-5">\n' +
                        '                            <a href="commodity.html?commodityId=' + item.commodityId + '">\n' +
                        '                            <img src="' + item.picture + '">\n' +
                        '                            <div class="eats_the_name">\n' +
                        '                                <p>' + item.commodityDescribe + '</p>\n' +
                        '                                <span>' + item.commodityName + '&nbsp;&nbsp;<i>¥</i><em>' + item.price + '</em>起</span>\n' +
                        '                            </div>\n' +
                        '                            </a>\n' +
                        '                        </div>';
                });
                $('#areaFood1').html(showInfo);
            }
        });
    };
    function getFood02() {
        $.getJSON(addFood02,function (data) {
            if (!data.success){
                var showInfo = '';
                data.areaFood.map(function (item,index) {
                    showInfo += '<div class="col-md-1-5">\n' +
                        '                            <a href="commodity.html?commodityId=' + item.commodityId + '">\n' +
                        '                            <img src="' + item.picture + '">\n' +
                        '                            <div class="eats_the_name">\n' +
                        '                                <p>' + item.commodityDescribe + '</p>\n' +
                        '                                <span>' + item.commodityName + '&nbsp;&nbsp;<i>¥</i><em>' + item.price + '</em>起</span>\n' +
                        '                            </div>\n' +
                        '                            </a>\n' +
                        '                        </div>';
                });
                $('#areaFood4').html(showInfo);
            }
        })
    };
    function getFood03() {
        $.getJSON(addFood03, function (data) {
            if (!data.success){
                var showInfo = '';
                data.areaFood.map(function (item,index) {
                    showInfo += '<div class="col-md-1-5">\n' +
                        '                            <a href="commodity.html?commodityId=' + item.commodityId + '">\n' +
                        '                            <img src="' + item.picture + '">\n' +
                        '                            <div class="eats_the_name">\n' +
                        '                                <p>' + item.commodityDescribe + '</p>\n' +
                        '                                <span>' + item.commodityName + '&nbsp;&nbsp;<i>¥</i><em>' + item.price + '</em>起</span>\n' +
                        '                            </div>\n' +
                        '                            </a>\n' +
                        '                        </div>';

                });
                $('#areaFood2').html(showInfo);
            }
        })
    };
    function getFood04() {
        $.getJSON(addFood04,function (data) {
            if (!data.success){
                var showInfo = '';
                data.areaFood.map(function (item,index) {
                    showInfo += '<div class="col-md-1-5">\n' +
                        '                            <a href="commodity.html?commodityId=' + item.commodityId + '">\n' +
                        '                            <img src="' + item.picture + '">\n' +
                        '                            <div class="eats_the_name">\n' +
                        '                                <p>' + item.commodityDescribe + '</p>\n' +
                        '                                <span>' + item.commodityName + '&nbsp;&nbsp;<i>¥</i><em>' + item.price + '</em>起</span>\n' +
                        '                            </div>\n' +
                        '                            </a>\n' +
                        '                        </div>';
                });
                $('#areaFood3').html(showInfo);
            }
        })
    };
}

function addInfo2() {
    // 综合排序
    var addFood11 = '/label/labelFood1';
    // 评分排序
    var addFood12 = '/label/labelFood2';
    // 销量排序
    var addFood13 = '/label/labelFood3';
    // 价格排序
    var addFood14 = '/label/labelFood4';
    getFood11();
    getFood12();
    getFood13();
    getFood14();
// 添加热门食品
    function getFood11() {
        $.getJSON(addFood11, function (data){
            if (!data.success){
                var showInfo = '';
                data.labelFood.map(function (item,index) {
                    showInfo += '<div class="col-md-1-5">\n' +
                        '                            <a href="commodity.html?commodityId=' + item.commodityId + '">\n' +
                        '                            <img src="' + item.picture + '">\n' +
                        '                            <div class="eats_the_name">\n' +
                        '                                <p>' + item.commodityDescribe + '</p>\n' +
                        '                                <span>' + item.commodityName + '&nbsp;&nbsp;<i>¥</i><em>' + item.price + '</em>起</span>\n' +
                        '                            </div>\n' +
                        '                            </a>\n' +
                        '                        </div>';
                });
                $('#areaFood1').html(showInfo);
            }
        });
    };
    function getFood12() {
        $.getJSON(addFood12,function (data) {
            if (!data.success){
                var showInfo = '';
                data.labelFood.map(function (item,index) {
                    showInfo += '<div class="col-md-1-5">\n' +
                        '                            <a href="commodity.html?commodityId=' + item.commodityId + '">\n' +
                        '                            <img src="' + item.picture + '">\n' +
                        '                            <div class="eats_the_name">\n' +
                        '                                <p>' + item.commodityDescribe + '</p>\n' +
                        '                                <span>' + item.commodityName + '&nbsp;&nbsp;<i>¥</i><em>' + item.price + '</em>起</span>\n' +
                        '                            </div>\n' +
                        '                            </a>\n' +
                        '                        </div>';
                });
                $('#areaFood4').html(showInfo);
            }
        })
    };
    function getFood13() {
        $.getJSON(addFood13, function (data) {
            if (!data.success){
                var showInfo = '';
                data.labelFood.map(function (item,index) {
                    showInfo += '<div class="col-md-1-5">\n' +
                        '                            <a href="commodity.html?commodityId=' + item.commodityId + '">\n' +
                        '                            <img src="' + item.picture + '">\n' +
                        '                            <div class="eats_the_name">\n' +
                        '                                <p>' + item.commodityDescribe + '</p>\n' +
                        '                                <span>' + item.commodityName + '&nbsp;&nbsp;<i>¥</i><em>' + item.price + '</em>起</span>\n' +
                        '                            </div>\n' +
                        '                            </a>\n' +
                        '                        </div>';

                });
                $('#areaFood2').html(showInfo);
            }
        })
    };
    function getFood14() {
        $.getJSON(addFood14,function (data) {
            if (!data.success){
                var showInfo = '';
                data.labelFood.map(function (item,index) {
                    showInfo += '<div class="col-md-1-5">\n' +
                        '                            <a href="commodity.html?commodityId=' + item.commodityId + '">\n' +
                        '                            <img src="' + item.picture + '">\n' +
                        '                            <div class="eats_the_name">\n' +
                        '                                <p>' + item.commodityDescribe + '</p>\n' +
                        '                                <span>' + item.commodityName + '&nbsp;&nbsp;<i>¥</i><em>' + item.price + '</em>起</span>\n' +
                        '                            </div>\n' +
                        '                            </a>\n' +
                        '                        </div>';
                });
                $('#areaFood3').html(showInfo);
            }
        })
    };
}